from selenium import webdriver
import time
from selenium.webdriver.common.by import By
def find_element():
  driver=webdriver.Chrome()
  driver.get("https://vip.ceshiren.com/#/ui_study/locate")
  time.sleep(10)
  try:
      # id
      id_element=driver.find_element(By.ID,"located_id")
      print(id_element.text)
    # class name
      class_name=driver.find_element(By.CLASS_NAME,"locate_class_name")
      print(class_name.text)

    # name
      name=driver.find_element(By.NAME,"located_name")
      print(name.text)
    # link test
      link_test=driver.find_element(By.LINK_TEXT,"link")
      print(link_test.text)
    # partial link test
      partial_link_test=driver.find_element(By.PARTIAL_LINK_TEXT,"partial")
      print(partial_link_test.text)
  
    # tag name
      tag_button=driver.find_element(By.XPATH,"//*[@id='app']/div/section/section/main/div/div[1]/div[6]/button")
      tag_name=tag_button.find_element(By.TAG_NAME,"span")
      print(tag_name.text)
    # css selector（绝对定位）
      css_selector=driver.find_element(By.CSS_SELECTOR,"#app > div > section > section > main > div > div.box2 > div.grandfather > button")
      print(css_selector.text)
    # xpath（绝对定位）
      xpath=driver.find_element(By.XPATH,"//*[@id='app']/div/section/section/main/div/div[2]/div[2]/button")  
      print(xpath.text)
  except Exception as e:
      print("定位失败")
  finally:
      driver.quit()


if __name__ == '__main__':
  find_element()